home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Telnet 2.7b5 / source / parse / vsem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-17  |  24.8 KB  |  926 lines  |  [TEXT/CWIE]

  1. /*
  2.  *
  3.  *      Virtual Screen Kernel Emulation Routines
  4.  *                      (vsem.c)
  5.  *  
  6.  *   National Center for Supercomputing Applications
  7.  *      by Gaige B. Paulsen
  8.  *
  9.  *    This file contains the private emulation calls for the NCSA
  10.  *  Virtual Screen Kernel.
  11.  *
  12.  *-----------------------------------------------------------------------------------
  13.  *    This also now contains Roland Mansson's code for printer redirection
  14.  *    Thanks for all of the work, Roland!
  15.  *-----------------------------------------------------------------------------------
  16.  *
  17.  *      Version Date    Notes
  18.  *      ------- ------  ---------------------------------------------------
  19.  *      0.01    861102  Initial coding -GBP
  20.  *      0.10    861111  Added/Modified VT emulator -GBP
  21.  *      0.50    861113  First compiled edition -GBP
  22.  *        2.1        871130    NCSA Telnet 2.1 -GBP
  23.  *        2.2     880715    NCSA Telnet 2.2 -GBP
  24.  *        2.6        12/92    Telnet 2.6: Fixed some VS stuff, and added LU changes
  25.  */
  26.  
  27. #ifdef MPW
  28. #pragma segment VS
  29. #endif
  30.  
  31.  
  32. #include "wind.h"
  33. #include "vsdata.h"
  34. #include "vskeys.h"
  35. #include "rsinterf.proto.h"
  36. #include "rsmac.proto.h"
  37. #include "vsintern.proto.h"
  38. #include "vsinterf.proto.h"
  39. #include "translate.proto.h"
  40. #include "maclook.proto.h"
  41. #include "printing.proto.h"
  42. #include "event.proto.h"
  43. #include "menuseg.proto.h"
  44.  
  45. #include "vsem.proto.h"
  46.  
  47. extern THPrint PrRecHandle;        /* LU - our print record handle from menu.c */
  48. extern Cursor *theCursors[];
  49. extern long        TempItemsDirID;
  50. extern short    TempItemsVRefNum;
  51. extern WindRec *screens;
  52.  
  53. void    VSunload(void) {}
  54.  
  55. /* LU - this is the start of the main LU changes for doing printer redirection     */
  56. /*     Once again I would like to thank Roland Mansson, of the Lund University 
  57.     Computing Center (Sweden) for all of his work on Telnet.   Not only for the 
  58.     national char support, but also for the printer redirection support, a new 
  59.     version of PrintPages, and everything else.  Thanks a lot, and keep up the
  60.     good work!!!        -SMB                                                    */
  61. /* LU - we have gotten the escape sequence to turn on printer redirection, so do so */ 
  62. void VSprON(void)
  63. {
  64.     char    tmp[100];                /* only for debugging */
  65.     OSErr    sts;
  66.     
  67.     putln ("printer redirection ON");
  68.     VSIw->prredirect = 1;
  69.     VSIw->prbuf = 0x00000000;
  70.     sprintf (VSIw->fname,"NCSA Telnet tempfile #%d",VSIwn);
  71.     c2pstr(VSIw->fname);                                    /* BYU 2.4.18 */
  72.  
  73.     if ((sts = HCreate(TempItemsVRefNum, TempItemsDirID, (StringPtr)VSIw->fname, '????', 'TEXT')) != noErr) {
  74.         if (sts != dupFNErr) {
  75.             SysBeep(1);
  76.             VSIw->prredirect = 0;
  77.             sprintf(tmp,"Create: ERROR %d",sts);
  78.             putln(tmp);
  79.             return;
  80.             }
  81.         }
  82.     if ((sts = HOpen(TempItemsVRefNum, TempItemsDirID, (StringPtr)VSIw->fname, fsRdWrPerm, &(VSIw->refNum))) != noErr) {
  83.         SysBeep(1);
  84.         VSIw->prredirect = 0;
  85.         sprintf(tmp,"FSOpen: ERROR %d",sts);
  86.         putln(tmp);
  87.         HDelete(TempItemsVRefNum, TempItemsDirID, (StringPtr)VSIw->fname);
  88.         return;
  89.         }
  90.     if (SetEOF(VSIw->refNum, 0L)) {
  91.         SysBeep(1);
  92.         VSIw->prredirect = 0;
  93.         putln("VSPRON:SETEOF ERROR");
  94.         HDelete(TempItemsVRefNum, TempItemsDirID, (StringPtr)VSIw->fname);
  95.         return;
  96.         }
  97. }
  98.  
  99.  
  100. /* LU - we just got the escape sequence to turn OFF redirection.  Take what we have
  101.         and dump it to the printer */
  102.         
  103. void VSprOFF(void)
  104. {
  105.     Str255        Title;
  106.     TPrStatus    prStatus;    /* Status record */
  107.     TPPrPort    prPort;        /* the Printer port */
  108.     OSErr        sts;
  109.     GrafPtr        savePort;
  110.     char        tmp[100];    /* only for debugging */
  111.     short        temp;        /* NCSA: SB - the screen # */
  112.     THPrint        PrRecHandle;
  113.     
  114.     putln ("printer redirection OFF");
  115.     if (VSIw->prredirect==0)            /* no redirection started! */
  116.         return;
  117.     VSIw->prredirect = 0;
  118.     GetPort (&savePort);                /* save old port */
  119.  
  120.     PrOpen();
  121.     
  122.     PrRecHandle = PrintSetupRecord();
  123.     
  124.     GetWTitle ((GrafPtr) RSgetwindow(VSIwn),Title);
  125.     SetCursor(theCursors[normcurs]);
  126.     
  127.     if (PrJobDialog(PrRecHandle)) {            /* Cancel the print if FALSE */
  128.         if ((sts=PrError()) != noErr){
  129.             sprintf(tmp,"PrJobDialog: ERROR %d",sts);
  130.             putln(tmp);
  131.             }
  132.         prPort=PrOpenDoc(PrRecHandle,0L,0L);
  133.         if ((sts=PrError()) != noErr) {
  134.             SysBeep(1);
  135.             sprintf(tmp,"PrOpenDoc: ERROR %d",sts); putln(tmp);
  136.         } else {
  137.             temp = findbyVS(VSIwn);                    /* NCSA: SB */
  138.             if (temp < 0)    {
  139.                 PrClose();                    /* NCSA: SB */
  140.                 DisposeHandle((Handle)PrRecHandle);
  141.                 return;                            /* NCSA: SB */
  142.                 }
  143.             printPages (prPort, PrRecHandle, Title, VSmaxwidth(VSIwn), NULL, VSIw->refNum, 0L,temp);
  144.             PrCloseDoc(prPort);
  145.             if ((sts=PrError()) != noErr) {
  146.                 sprintf(tmp,"PrCloseDoc: ERROR %d",sts);
  147.                 putln(tmp);
  148.                 }
  149.             if (((*PrRecHandle)->prJob.bJDocLoop == bSpoolLoop) && (PrError()==0)) {
  150.                 PrPicFile(PrRecHandle,0L,0L,0L,&prStatus); /* Spool if necessary… */
  151.                 if ((sts=PrError()) != noErr) {
  152.                     sprintf(tmp,"PrPicFile: ERROR %d",sts);
  153.                     putln(tmp);
  154.                     }
  155.             }
  156.         }
  157.     }
  158.     
  159.     PrClose();
  160.     DisposeHandle((Handle)PrRecHandle);
  161.     
  162.     SetPort (savePort);                /* restore old port */
  163.     if ((sts=FSClose (VSIw->refNum)) != noErr) {
  164.         SysBeep(1);
  165.         sprintf(tmp,"FSClose: ERROR %d",sts); putln(tmp);
  166.     }
  167.     VSIw->refNum = -1;
  168.  
  169.     if ((sts=HDelete(TempItemsVRefNum, TempItemsDirID, (StringPtr)VSIw->fname)) != noErr) {
  170.         SysBeep(1);
  171.         sprintf(tmp,"HDelete: ERROR %d",sts); putln(tmp);
  172.     }
  173.     updateCursor(1);
  174. }
  175.  
  176.  
  177. #define ENDOFPRT     '\033[4i'        /* <ESC>[4i   (0x1b5b3469) */
  178.  
  179. void VSpr(unsigned char **pc, short *pctr)
  180. {
  181.     long count;                /* number of chars to print to file */
  182.     char *start;             /* original start of buffer */
  183.     OSErr sts;
  184.     char tmp[100];            /* only for debugging */
  185.     short rdy;                /* true if <ESC>[4i */
  186.  
  187.     count=0;                
  188.     start=(char *)*pc;    
  189.     rdy=0;
  190.  
  191.     while ((*pctr>0) && (!rdy)) {
  192.         VSIw->prbuf=(VSIw->prbuf<<8) + **pc;
  193.         if (VSIw->prbuf==ENDOFPRT) {            /* i.e. no more redirection */
  194.             rdy=1;
  195.             count--;                    /* will be incremented again below */
  196.         }
  197.         count++;
  198.         (*pc)++;
  199.         (*pctr)--;
  200.     }
  201.  
  202.     trbuf_nat_mac ((unsigned char *)start,count, screens[findbyVS(VSIwn)].national);
  203.     if ((sts=FSWrite(VSIw->refNum,&count,start)) != noErr) {
  204.         SysBeep(1);
  205.         sprintf(tmp,"FSWrite: ERROR %d",sts); putln(tmp);
  206.     }
  207.     if (rdy || sts)
  208.         VSprOFF();
  209. }
  210.  
  211.  
  212.  
  213. /* LU - that is the end of the new routines needed for printer redirection     */
  214. /* LU - now we just patch up VSem() to use this code, and were done!         */
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222. void VSem
  223.   (
  224.     unsigned char *c, /* pointer to character string */
  225.     short ctr /* length of character string */
  226.   )
  227.   /* basic routine for placing characters on a virtual screen, and
  228.     interpreting control characters and escape sequences. Simple
  229.     interpretation of controls & escapes is done here, while the
  230.     harder stuff is done by calling VSIxx routines in vsintern.c. */
  231. {
  232.     register short sx;
  233.     register short escflg; /* state of escape sequence interpretation */
  234.     short insert, attrib, extra, offend;
  235.     char  *current, *start;
  236.     unsigned short *acurrent;
  237.     escflg = VSIw->escflg;
  238.  
  239.     while (ctr > 0)
  240.       {
  241.         if (VSIw->prredirect)    /* PR - printer redirection? */
  242.         VSpr(&c,&ctr);            /* PR -if yes, call VSpr */
  243.                                 /* PR - when we return from VSpr there may (ctr!=0) … */
  244.                                 /* PR - … or may not (ctr==0) be chars left in *c to print */
  245.         while ((escflg == 0) && (ctr > 0) && (*c < 32))
  246.           {
  247.             switch (*c)
  248.               {
  249.                 case 0x1b: /* esc */
  250.                     escflg++;
  251.                     break;
  252.                 case 0x0e: /* shift out */
  253.                     if (VSIw->G1)
  254.                         VSIw->attrib = VSgraph(VSIw->attrib);
  255.                     else
  256.                         VSIw->attrib = VSnotgraph(VSIw->attrib);
  257.                     VSIw->charset = 1;
  258.                     break;
  259.                 case 0x0f: /* shift in */
  260.                     if (VSIw->G0)
  261.                         VSIw->attrib = VSgraph(VSIw->attrib);
  262.                     else
  263.                         VSIw->attrib = VSnotgraph(VSIw->attrib);
  264.                     VSIw->charset = 0;
  265.                     break;
  266.                 case 0x07: /* bell */
  267.                     RSbell(VSIwn);
  268.                     break;
  269.                 case 0x08: /* backspace */
  270.                     VSIw->x--;
  271.                     if (VSIw->x < 0)
  272.                       /* hit left margin */
  273.                         VSIw->x = 0;
  274.                     break;
  275.                 case 0x0c: /* ff */
  276.                     VSIindex();
  277.                     break;
  278.                 case 0x09: /* ht */        /* Later change for versatile tabbing */
  279.                     VSItab();
  280.                     VScapture(c,1);                
  281.                     break;
  282.                 case 0x0a: /* lf */
  283.                     VSIindex();
  284.                     break;
  285.                 case 0x0d: /* cr */
  286.                     VSIw->x = 0;
  287.                     VScapture(c,1);                
  288.                     break;
  289.                 case 0x0b: /* vt */
  290.                     VSIindex();
  291.                     break;
  292.               } 
  293.             c++;
  294.             ctr--;
  295.           } 
  296.         if ((escflg == 0) && (ctr > 0) && (*c & 0x80) && (*c < 0xA0)
  297.             && (screens[findbyVS(VSIwn)].vtemulation == 1))    // VT220 eightbit starts here
  298.         {                                            
  299.             switch (*c)                                
  300.             {                                    
  301.                 case 0x84: /* ind */        //same as ESC D
  302.                     VSIindex();        
  303.                     goto ShortCut;            
  304.                 case 0x85: /* nel */        //same as ESC E
  305.                     VSIw->x = 0;                
  306.                     VSIindex();                
  307.                     goto ShortCut;            
  308.                 case 0x88: /* hts */        //same as ESC H 
  309.                     VSIw->tabs[VSIw->x] = 'x';    
  310.                     goto ShortCut;    
  311.                 case 0x8d: /* ri */            //same as ESC M 
  312.                     VSIrindex();        
  313.                     goto ShortCut;    
  314.                 case 0x9b: /* csi */        //same as ESC [ 
  315.                     VSIapclear();            
  316.                     escflg = 2;            
  317.                     c++;            //CCP            
  318.                     ctr--;                    
  319.                     break;                        
  320.                 case 0x86: /* ssa */            // - same as ESC F */
  321.                 case 0x87: /* esa */            // - same as ESC G */
  322.                 case 0x8e: /* ss2 */            // - same as ESC N */
  323.                 case 0x8f: /* ss3 */            // - same as ESC O */
  324.                 case 0x90: /* dcs */            // - same as ESC P */
  325.                 case 0x93: /* sts */            // - same as ESC S */
  326.                 case 0x96: /* spa */            // - same as ESC V */
  327.                 case 0x97: /* epa */            // - same as ESC W */
  328.                 case 0x9d: /* osc */            // - same as ESC ] */
  329.                 case 0x9e: /* pm */                // - same as ESC ^ */
  330.                 case 0x9f: /* apc */            // - same as ESC _ */
  331.                 default:
  332.                     goto ShortCut;                
  333.             }                     
  334.         }//end if vt220
  335.         while ((ctr > 0) && (escflg == 0) && (*c >= 32) &&!((*c & 0x80) && (*c < 0xA0)
  336.             && (screens[findbyVS(VSIwn)].vtemulation == 1)))
  337.         { //loop around, printing lines of text one at a time
  338.           
  339.             start = &VSIw->linest[VSIw->y]->text[VSIw->x]; /* start of area needing redrawing */
  340.             current = start; /* where to put next char */
  341.             acurrent = &VSIw->attrst[VSIw->y]->text[VSIw->x]; /* where to put corresponding attribute byte */
  342.             attrib = VSIw->attrib; /* current writing attribute */
  343.             insert = VSIw->IRM; /* insert mode (boolean) */
  344.             offend = 0; /* wrapped to next line (boolean) */
  345.             extra = 0; /* overwriting last character of line  */
  346.             sx = VSIw->x; /* starting column of area needing redrawing */
  347.             if (VSIw->x > VSIw->maxwidth)
  348.             {
  349.                 if (VSIw->DECAWM)
  350.                 { // wrap to next line 
  351.                     VSIw->x = 0;
  352.                     VSIindex();
  353.                 }
  354.                 else //stay at right margin 
  355.                     VSIw->x = VSIw->maxwidth;
  356.                 
  357.                 current = start = &VSIw->linest[VSIw->y]->text[VSIw->x];
  358.                 acurrent = &VSIw->attrst[VSIw->y]->text[VSIw->x];
  359.                 sx = VSIw->x;
  360.               } /* if */
  361.             while ((ctr > 0) && (*c >= 32) && (offend == 0) && !((*c & 0x80) && (*c < 0xA0)
  362.             && (screens[findbyVS(VSIwn)].vtemulation == 1)))
  363.             {//Write characters on a single line
  364.                 trbuf_nat_mac(c,1, screens[findbyVS(VSIwn)].national);    //translate to national chars 
  365.                 if (insert) //make room for the char 
  366.                     VSIinschar(1);
  367.                 *current = *c;
  368.                 *acurrent = attrib;
  369.                 c++;
  370.                 ctr--;
  371.                 if (VSIw->x < VSIw->maxwidth) //advance the cursor position
  372.                 {
  373.                     acurrent++;
  374.                     current++;
  375.                     VSIw->x++;
  376.                 }
  377.                 else //hit right margin
  378.                 {
  379.                     if (VSIw->DECAWM) //autowrap to start of next line
  380.                     {
  381.                         VSIw->x++;
  382.                         offend = 1; // terminate inner loop 
  383.                     }
  384.                     else //stay at right margin
  385.                     {
  386.                         VSIw->x = VSIw->maxwidth;
  387.                         extra = 1; // cursor position doesn't advance 
  388.                     } 
  389.                 } 
  390.             } //we've got a line full of text in the virtual screen
  391.               //now update the screen to show what we've done
  392.               extra += VSIw->x - sx;
  393.             if (insert)
  394.                 RSinsstring(VSIwn, VSIw->x - extra, VSIw->y,VSIw->attrib, extra, start);
  395.             else
  396.             { 
  397.                 short x2,y2,offset, sxCopy=sx,yCopy = VSIw->y, extraCopy = extra;
  398.                 
  399.                 if (!VSIclip(&sxCopy, &yCopy, &x2, &y2, &extraCopy, &offset))
  400.                     RSdraw(VSIwn, sxCopy,yCopy, VSIw->attrib,extraCopy,(char *) (start + offset));
  401.             }
  402.             //if (RSisInFront(VSIwn)) //CCP if we are front window, validate the screen
  403.             //    RSvalidateRect(VSIwn);
  404.             VScapture((unsigned char *) start, extra);
  405.           } /* while */
  406.  
  407.         while((ctr > 0) && (escflg == 1))
  408.           { /* basic escape sequence processing */
  409.             switch (*c)
  410.               {
  411.                 case 0x08:
  412.                     VSIw->x--;
  413.                     if (VSIw->x < 0)
  414.                         VSIw->x = 0;
  415.                     break;
  416.                 case '[': /* csi */
  417.                     VSIapclear();
  418.                     escflg++;
  419.                     break;
  420.                 case '7':
  421.                     VSIsave();
  422.                     goto ShortCut;                /* BYU 2.4.12 */
  423.                 case '8':
  424.                     VSIrestore();
  425.                     goto ShortCut;                /* BYU 2.4.12 */
  426.                 case 'c':
  427.                     VSIreset();
  428.                     break;
  429.                 case 'D':
  430.                     VSIindex();
  431.                     goto ShortCut;                /* BYU 2.4.12 */
  432.                 case 'E':
  433.                     VSIw->x = 0;
  434.                     VSIindex();
  435.                     goto ShortCut;                /* BYU 2.4.12 */
  436.                 case 'M':
  437.                     VSIrindex();
  438.                     goto ShortCut;                /* BYU 2.4.12 */
  439.                 case '>':
  440.                     VSIw->DECPAM = 0;
  441.                     goto ShortCut;                /* BYU 2.4.12 */
  442.                 case '=':
  443.                     VSIw->DECPAM = 1;
  444.                     goto ShortCut;                /* BYU 2.4.12 */
  445.                 case 'Z':
  446.                     VTsendident();
  447.                     goto ShortCut;                /* BYU 2.4.12 */
  448.                 case ' ':                        /* BYU 2.4.12 */
  449.                 case '*':                        /* BYU 2.4.12 */
  450.                 case '#':
  451.                     escflg = 3;
  452.                     break;
  453.                 case '(':
  454.                     escflg = 4;
  455.                     break;
  456.                 case ')':
  457.                     escflg = 5;
  458.                     break;
  459.                 case 'H':
  460.                     VSIw->tabs[VSIw->x] = 'x';
  461.                     goto ShortCut;                /* BYU 2.4.12 */
  462. #ifdef CISB
  463.                 case 'I':
  464.                     bp_ESC_I();
  465.                     break;
  466. #endif CISB
  467.                 case ']':                                // WNR - XTerm
  468.                     if (screens[findbyVS(VSIwn)].Xterm)    // WNR - XTerm
  469.                         escflg = 6;                        // WNR - XTerm
  470.                     break;                                // WNR - XTerm
  471.                     
  472.                 default:
  473.                     goto ShortCut;                /* BYU 2.4.12 */
  474.               } /* switch */
  475.             c++;
  476.             ctr--;
  477.           } /* while */
  478.         while ((escflg == 2) && (ctr > 0))
  479.           { /* "control sequence" processing */
  480.             switch (*c)
  481.               {
  482.                 case 0x08:
  483.                     VSIw->x--;
  484.                     if (VSIw->x < 0)
  485.                         VSIw->x = 0;
  486.                     break;
  487.                 case '0':
  488.                 case '1':
  489.                 case '2':
  490.                 case '3':
  491.                 case '4':
  492.                 case '5':
  493.                 case '6':
  494.                 case '7':
  495.                 case '8':
  496.                 case '9':
  497.                   /* parse numeric parameter */
  498.                     if (VSIw->parms[VSIw->parmptr] < 0)
  499.                         VSIw->parms[VSIw->parmptr] = 0;
  500.                         
  501.                     VSIw->parms[VSIw->parmptr] = VSIw->parms[VSIw->parmptr] * 10;
  502.                     VSIw->parms[VSIw->parmptr] += *c - '0';
  503.                     break;
  504.                 case '?':
  505.                   /* DEC-private control sequence */
  506.                     VSIw->parms[VSIw->parmptr++] = -2;
  507.                     break;
  508.                 case ';':
  509.                   /* parameter separator */
  510.                     VSIw->parmptr++;
  511.                     break;
  512.                 case 'A': /* cursor up */
  513. #if 1                                                        /* BYU */
  514.                     if (VSIw->parms[0]<1) VSIw->y--;        /* BYU */
  515.                     else VSIw->y-=VSIw->parms[0];            /* BYU */
  516.                     if ( VSIw->y < 0 ) VSIw->y=0;            /* BYU */
  517.                     if (VSIw->y < VSIw->top)                /* NCSA: SB */
  518.                         VSIw->y = VSIw->top;                /* NCSA: SB */
  519.                         
  520. #else                                                        /* BYU */
  521.                     if (VSIw->y < VSIw->top)
  522.                       {
  523.                       /* outside scrolling region */
  524.                         if (VSIw->parms[0] < 1)
  525.                             VSIw->y--;
  526.                         else
  527.                             VSIw->y -= VSIw->parms[0];
  528.                       }
  529.                     else
  530.                       {
  531.                       /* don't leave scrolling region */
  532.                         if (VSIw->parms[0] < 1)
  533.                             VSIw->y--;
  534.                         else
  535.                             VSIw->y -= VSIw->parms[0];
  536.                         if (VSIw->y < VSIw->top)
  537.                             VSIw->y = VSIw->top;
  538.                       }
  539. #endif                                                        /* BYU */
  540.                     VSIrange();
  541.                     goto ShortCut;                /* BYU 2.4.12 */
  542.                 case 'B': /* cursor down */
  543. #if 1                                                        /* BYU */
  544.                     if (VSIw->parms[0]<1) VSIw->y++;        /* BYU */
  545.                     else VSIw->y+=VSIw->parms[0];            /* BYU */
  546.                     if (VSIw->y > VSIw->bottom)                /* NCSA: SB */
  547.                         VSIw->y = VSIw->bottom;                /* NCSA: SB */
  548.                         
  549. #else                                                        /* BYU */
  550.                     if (VSIw->y > VSIw->bottom)
  551.                       {
  552.                       /* outside scrolling region */
  553.                         if (VSIw->parms[0] < 1)
  554.                             VSIw->y++;
  555.                         else
  556.                             VSIw->y += VSIw->parms[0];
  557.                       }
  558.                     else
  559.                       {
  560.                       /* don't leave scrolling region */
  561.                         if (VSIw->parms[0] < 1)
  562.                             VSIw->y++;
  563.                         else
  564.                             VSIw->y += VSIw->parms[0];
  565.                         if (VSIw->y > VSIw->bottom)
  566.                             VSIw->y = VSIw->bottom;
  567.                       }
  568. #endif                                                        /* BYU */
  569.                     VSIrange();
  570.                     goto ShortCut;                /* BYU 2.4.12 */
  571.                 case 'C': /* cursor right */
  572.                     if (VSIw->parms[0] < 1)
  573.                         VSIw->x++;
  574.                     else
  575.                         VSIw->x += VSIw->parms[0];
  576.                     VSIrange();
  577.                     if (VSIw->x > VSIw->maxwidth)
  578.                         VSIw->x = VSIw->maxwidth;
  579.                     goto ShortCut;                /* BYU 2.4.12 */
  580.                 case 'D': /* cursor left */
  581.                     if (VSIw->parms[0] < 1)
  582.                         VSIw->x--;
  583.                     else
  584.                         VSIw->x -= VSIw->parms[0];
  585.                     VSIrange();
  586.                     goto ShortCut;                /* BYU 2.4.12 */
  587.                 case 'f':
  588.                 case 'H':
  589.                   /* absolute cursor positioning */
  590.                     VSIw->x = VSIw->parms[1] - 1;
  591.                     if (VSIw->DECORG)
  592.                       /* origin mode -- position relative to top of scrolling region */
  593.                         VSIw->y = VSIw->parms[0] - 1 + VSIw->top;
  594.                     else
  595.                         VSIw->y = VSIw->parms[0] - 1;
  596.                     /*    Don't use actual VSIrange 'cause it will wrap us to first column if 
  597.                         we are past screen edge.  This causes "resize" to break */
  598.                     if (VSIw->x < 0)                        /* JMB 2.6 */
  599.                         VSIw->x = 0;                        /* JMB 2.6 */
  600.                     if (VSIw->x > (VSIw->maxwidth))            /* JMB 2.6 */
  601.                         VSIw->x = VSIw->maxwidth;            /* JMB 2.6 */
  602.                     if (VSIw->y < 0)                        /* JMB 2.6 */
  603.                         VSIw->y = 0;                        /* JMB 2.6 */
  604.                     if (VSIw->y > VSIw->lines)                /* JMB 2.6 */
  605.                         VSIw->y = VSIw->lines;                /* JMB 2.6 */
  606.                     if ((VSIw->forcesave)&&(VSIw->y == 0)&&(VSIw->x == 0)) //CCP better FORCESAVE
  607.                         VSIw->possibleForce = TRUE;
  608.  
  609.                     goto ShortCut;                /* BYU 2.4.12 */
  610.                 case 'i':                                            /* PR: media copy */
  611.                     if (VSIw->parms[VSIw->parmptr]==5) {            /* PR */
  612.                         /*c++; ctr--; */                            /* PR */            
  613.                         VSprON();    /* PR - set status and open temp file etc */
  614.                                     /* PR - chars will be redirected at top of loop … */
  615.                                     /* PR - … in this procedure */
  616.                     }                /* PR */
  617.                     escflg = 0;        /* PR */
  618.                     break;            /* PR */
  619.                 case 'K':
  620.                   /* erase to beginning/end/whole of line */
  621.                     switch (VSIw->parms[0])
  622.                       {
  623.                         case -1:
  624.                         case  0:
  625.                             VSIeeol();
  626.                             break;
  627.                         case  1:
  628.                             VSIebol();
  629.                             break;
  630.                         case  2:
  631.                             VSIel(-1);
  632.                             break;
  633.                         default:
  634.                             goto ShortCut;        /* BYU 2.4.12 */
  635.                       } /* switch */
  636.                     goto ShortCut;                /* BYU 2.4.12 */
  637.                 case 'J':
  638.                   /* erase to beginning/end/whole of screen */
  639.                     switch (VSIw->parms[0])
  640.                       {
  641.                         case -1:
  642.                         case  0:
  643.                             VSIeeos();
  644.                             break;
  645.                         case  1:
  646.                             VSIebos();
  647.                             break;
  648.                         case  2:
  649.                             VSIes();
  650.                             break;
  651.                         default:
  652.                             goto ShortCut;        /* BYU 2.4.12 */
  653.                       } /* switch */
  654.                     goto ShortCut;                /* BYU 2.4.12 */
  655.                 case 'm':
  656.                   /* set/clear attributes */
  657.                   {
  658.                     short temp = 0;
  659.                     while (temp <= VSIw->parmptr)
  660.                       {
  661.                         short p;
  662.                         
  663.                         if (VSIw->parms[VSIw->parmptr] < 0)
  664.                             VSIw->parms[VSIw->parmptr] = 0;
  665.                           
  666.                           p = VSIw->parms[temp];
  667.                           if (p == 0) 
  668.                               VSIw->attrib &= 0x80; //all off
  669.                           else if (p<8) 
  670.                               VSIw->attrib |= VSa(p);//set an attribute
  671.                         else if (p>21 && p<28) 
  672.                             VSIw->attrib &= ~VSa(p-20); //clear an attribute
  673.                           else if (screens[findbyVS(VSIwn)].ANSIgraphics) 
  674.                           {
  675.                              if (p>=30 && p<38)
  676.                                 VSIw->attrib = (VSIw->attrib&~0x0700) | ((p-30)<<8) | 0x0800;
  677.                             else if (p>=40 && p<48)
  678.                                 VSIw->attrib = (VSIw->attrib&~0x7000) | ((p-40)<<12) | 0x8000;
  679.                         }
  680.                         temp++;
  681.                       } /* while */
  682.                   }
  683.                   goto ShortCut;                /* BYU 2.4.12 */
  684.                 case 'q':
  685.                   /* flash dem LEDs. What LEDs? */
  686.                     goto ShortCut;                /* BYU 2.4.12 */
  687.                 case 'c':
  688.                     VTsendident();
  689.                     goto ShortCut;                /* BYU 2.4.12 */
  690.                 case 'n':
  691.                     switch (VSIw->parms[0])
  692.                       {
  693.                         case 5:
  694.                             VTsendstat();
  695.                             break;
  696.                         case 6:
  697.                             VTsendpos();
  698.                             break;
  699.                       } /* switch */
  700.                     goto ShortCut;                /* BYU 2.4.12 */
  701.                 case 'L':
  702.                     if (VSIw->parms[0] < 1)
  703.                         VSIw->parms[0] = 1;
  704.                     VSIinslines(VSIw->parms[0], -1);
  705.                     goto ShortCut;                /* BYU 2.4.12 */
  706.                 case 'M':
  707.                     if (VSIw->parms[0] < 1)
  708.                         VSIw->parms[0] = 1;
  709.                     VSIdellines(VSIw->parms[0], -1);
  710.                     goto ShortCut;                /* BYU 2.4.12 */
  711.                 case '@':
  712.                     if (VSIw->parms[0] < 1)
  713.                         VSIw->parms[0] = 1;
  714.                     VSIinschar(VSIw->parms[0]);
  715.                     VSredrawLine(VSIwn); //redraws current line
  716.                     goto ShortCut;
  717.                 case 'P':
  718.                     if (VSIw->parms[0] < 1)
  719.                         VSIw->parms[0] = 1;
  720.                     VSIdelchars(VSIw->parms[0]);
  721.                     goto ShortCut;                /* BYU 2.4.12 */
  722.                 case 'r':
  723.                   /* set scrolling region */
  724.                     if (VSIw->parms[0] < 0)
  725.                         VSIw->top = 0;
  726.                     else
  727.                         VSIw->top = VSIw->parms[0] - 1;
  728.                     if (VSIw->parms[1] < 0)
  729.                         VSIw->bottom = VSIw->lines;
  730.                     else
  731.                         VSIw->bottom = VSIw->parms[1] - 1;
  732.                     if (VSIw->top < 0)
  733.                         VSIw->top = 0;
  734.                     if (VSIw->top > VSIw->lines - 1)
  735.                         VSIw->top = VSIw->lines - 1;
  736.                     if (VSIw->bottom < 1)
  737.                         VSIw->bottom = VSIw->lines;
  738.                     if (VSIw->bottom > VSIw->lines)
  739.                         VSIw->bottom = VSIw->lines;
  740.  
  741.                     if (VSIw->top >= VSIw->bottom)            /* NCSA: SB */
  742.                         {                                    /* NCSA: SB */
  743.                         if (VSIw->bottom >=1)                /* NCSA: SB */
  744.                             VSIw->top = VSIw->bottom -1;    /* NCSA: SB */
  745.                         else VSIw->bottom = VSIw->top +1;    /* NCSA: SB */
  746.                         }                                    /* NCSA: SB */
  747.                  
  748.                      VSIw->x = 0;
  749.                     VSIw->y = 0;
  750.                     if (VSIw->DECORG)
  751.                         VSIw->y = VSIw->top;    /* origin mode relative */
  752.                     goto ShortCut;                /* BYU 2.4.12 */
  753.                 case 'h':
  754.                   /* set options */
  755.                     VSIsetoption(1);
  756.                     goto ShortCut;                /* BYU 2.4.12 */
  757.                 case 'l':
  758.                   /* reset options */
  759.                     VSIsetoption(0);
  760.                     goto ShortCut;                /* BYU 2.4.12 */
  761.                 case 'g':
  762.                     if (VSIw->parms[0] == 3)
  763.                       /* clear all tabs */
  764.                         VSItabclear();
  765.                     else if (VSIw->parms[0] <= 0)
  766.                       /* clear tab at current position */
  767.                         VSIw->tabs[VSIw->x] = ' ';
  768.                     goto ShortCut;                /* BYU 2.4.12 */
  769.                 case '!':                        /* BYU 2.4.12 - More private DEC stuff? */
  770.                 case '\'':                        /* BYU 2.4.12 - More private DEC stuff? */
  771.                 case '\"':                        /* BYU 2.4.12 - More private DEC stuff? */
  772.                     escflg++;                    /* BYU 2.4.12 */
  773.                     break;                        /* BYU 2.4.12 */
  774.                 default:            /* Dang blasted strays... */
  775.                     goto ShortCut;                /* BYU 2.4.12 */
  776.               } /* switch */
  777.             c++;
  778.             ctr--;
  779.           } /* while */
  780.  
  781.         while ((escflg == 3) && (ctr > 0))
  782.           {    /* "#" handling */
  783.           /* no support for double-width and double-height characters yet */
  784.             switch (*c)
  785.               {
  786.                 case 0x08:
  787.                     VSIw->x--;
  788.                     if (VSIw->x < 0)
  789.                         VSIw->x = 0;
  790.                     break;
  791.                 case '8': /* alignment display */
  792.                     VTalign();
  793.                     goto ShortCut;                /* BYU 2.4.12 */
  794.                 default:
  795.                     goto ShortCut;                /* BYU 2.4.12 */
  796.               } /* switch */
  797.             c++;
  798.             ctr--;
  799.           } /* while */
  800.  
  801.         while ((escflg == 4) && (ctr > 0))
  802.           {    /* "(" handling (selection of G0 character set) */
  803.             switch (*c)
  804.               {
  805.                 case 0x08:
  806.                     VSIw->x--;
  807.                     if (VSIw->x < 0)
  808.                         VSIw->x = 0;
  809.                     break;
  810.                 case 'A': /* UK */
  811.                 case 'B': /* US */
  812.                 case '1': /* "soft" */
  813.                     VSIw->G0 = 0;
  814.                     if (!VSIw->charset)
  815.                         VSIw->attrib = VSnotgraph(VSIw->attrib);
  816.                     goto ShortCut;                /* BYU 2.4.12 */
  817.                 case '0': /* DEC special graphics */
  818.                 case '2': /* "soft" */
  819.                     VSIw->G0 = 1;
  820.                     if (!VSIw->charset)
  821.                         VSIw->attrib = VSgraph(VSIw->attrib);
  822.                     goto ShortCut;                /* BYU 2.4.12 */
  823.                 default:
  824.                     goto ShortCut;                /* BYU 2.4.12 */
  825.               } /* switch */
  826.             c++;
  827.             ctr--;
  828.           } /* while */
  829.     
  830.         while ((escflg == 5) && (ctr > 0))
  831.           {    /* ")" handling (selection of G1 character set) */
  832.             switch (*c)
  833.               {
  834.                 case 0x08:
  835.                     VSIw->x--;
  836.                     if (VSIw->x < 0)
  837.                         VSIw->x = 0;
  838.                     break;
  839.                 case 'A': /* UK */
  840.                 case 'B': /* US */
  841.                 case '1': /* "soft" */
  842.                     VSIw->G1 = 0;
  843.                     if (VSIw->charset)
  844.                         VSIw->attrib = VSnotgraph(VSIw->attrib);
  845.                     goto ShortCut;                /* BYU 2.4.12 */
  846.                 case '0': /* DEC special graphics */
  847.                 case '2': /* "soft" */
  848.                     VSIw->G1 = 1;
  849.                     if (VSIw->charset)
  850.                         VSIw->attrib = VSgraph(VSIw->attrib);
  851.                     goto ShortCut;                /* BYU 2.4.12 */
  852.                 default:
  853.                     goto ShortCut;                /* BYU 2.4.12 */
  854.               } /* switch */
  855.             c++;
  856.             ctr--;
  857.           } /* while */
  858.  
  859.         // Handle XTerm rename functions, code contributed by Bill Rausch
  860.         // Modified by JMB to handle ESC]2; case as well.
  861.         if( (escflg >= 6) && (ctr > 0) ) {
  862.             static char *tmp;
  863.             static Str255 newname;
  864.           
  865.         if( (escflg == 6) && ((*c == '0') || (*c == '2'))) {
  866.             escflg++;
  867.             c++;
  868.             ctr--;
  869.             }
  870.         if( (escflg == 7 ) && (ctr > 0) && (*c == ';') ) {
  871.             ctr--;
  872.             c++;
  873.             escflg++;
  874.             newname[0] = 0;
  875.             tmp = (char *)&newname[1];
  876.             }
  877.         
  878.         while( (escflg == 8) && (ctr > 0) && (*c != 07) && (*c != 033)) {
  879.             if(*newname < 255)
  880.             {
  881.                  *tmp++ = *c;
  882.                 (*newname)++;
  883.             }
  884.             c++;
  885.             ctr--;
  886.         }
  887.         if( (escflg == 8) && (*c == 07 || *c == 033) && (ctr > 0) ) {
  888.             set_new_window_name( newname, RSgetwindow(VSIwn) );
  889.                if(*c != 07)
  890.             {
  891.             /* This will be undone in the ShortCut below. */
  892.                 c--;
  893.                 ctr++;
  894.             }
  895.             goto ShortCut;
  896.         }
  897. } /* if */
  898.  
  899. /*        
  900.         
  901.         while( (escflg == 8) && (ctr > 0) && (*c != 07) ) {
  902.             *tmp++ = *c++;
  903.             ctr--;
  904.             (*newname)++;
  905.             }
  906.         if( (escflg == 8) && (*c == 07) && (ctr > 0) ) {
  907.             set_new_window_name( newname, RSgetwindow(VSIwn) );
  908.             goto ShortCut;
  909.             }
  910.         } /* if */
  911.         
  912.         
  913.         if ((escflg > 2) && (ctr > 0))
  914.           {
  915. ShortCut:                        /* BYU 2.4.12 - well, sacrificing style for speed */
  916.             if ((VSIw->possibleForce)&&(*c != 'H')) //CCP better forcesave
  917.                 VSIw->possibleForce = FALSE;
  918.             escflg = 0;
  919.             c++;
  920.             ctr--;
  921.           } /* if */
  922.       } /* while (ctr > 0) */
  923.     VSIw->escflg = escflg;
  924.   } /* VSem */
  925.  
  926.